﻿using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Mysoft.MyCM.Web.Controllers
{
	public class CustomerController : MSharedBaseController
	{
		public ActionResult Switch(string returnUrl)
		{
			if (string.IsNullOrEmpty(returnUrl)) returnUrl = string.Format("{0}:\\{1}", Request.Url.Scheme, Request.Url.Authority);
			ViewBag.ReturnUrl = returnUrl;
			// 获取区域信息集合

			Business.Scm.AreaBLL areaBLL = new Business.Scm.AreaBLL();
			Business.Scm.CustomBLL customBLL = new Business.Scm.CustomBLL();
			List<Scm.Area> areas = areaBLL.GetAllAreas().Where(a=>!a.AreaGUID.Equals(Guid.Empty)).OrderBy(a => a.AreaName).ToList();
			// 获取区域对应的客户信息
			areas.ForEach(a =>
			{
				a.Customs = customBLL.GetCustomsOfArea(a.AreaGUID).OrderBy(c => c.CustomName).ToList();
			});
			dynamic model = new ExpandoObject();
			model.Areas = areas;
			return View(model);
		}
	}
}